/*
2021-7-16
https://www.acwing.com/problem/content/description/1291/
*/
#include<iostream>

using namespace std;
typedef long long ll;
const int mod=200907;

int qpow(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1)
        {
            res=(ll)res*a%mod;
        }
        a=(ll)a*a%mod;
        b>>=1;
    }
    return res;
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int a,b,c,k;
        cin>>a>>b>>c>>k;
        if(c-b==b-a) cout<<(a+(ll)(k-1)*(b-a))%mod<<endl;
        else
        {
            cout<<(ll)a*qpow(b/a,k-1)%mod<<endl;
        }
    }
    return 0;
}

